import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';
import 'package:distribution_mall_flutter/constant/point_constant.dart';
import 'package:distribution_mall_flutter/entity/order/list/order_list_entity.dart';
import 'package:distribution_mall_flutter/entity/order/order.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/order_cancel.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/order_more.dart';
import 'package:distribution_mall_flutter/provider/order/common.dart';
import 'package:distribution_mall_flutter/provider/order/order_detail.dart';
import 'package:distribution_mall_flutter/provider/order/order_list.dart';
import 'package:distribution_mall_flutter/router/router.dart';
import 'package:distribution_mall_flutter/utils/common_third.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:distribution_mall_flutter/utils/firebase/firebase_analytics_utils.dart';
import 'package:distribution_mall_flutter/router/router.gr.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ContentCardFooter extends ConsumerWidget {
  final Item data;
  const ContentCardFooter({super.key, required this.data});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    List<SaleReasonEntity> list =
        ref.watch(orderCommonProvider.select((value) => value.reasonList));

    return Padding(
      padding: const EdgeInsets.only(top: EdgeConstant.edge20),
      child: DefaultTextStyle(
          style: const TextStyle(
              color: ColorConstant.black89, fontSize: FontConstant.f12),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Visibility(
                visible: ref.read(orderDetailProvider.notifier).showMore(data),
                child: OrderMore(
                    distributionOrderId: data.distributionOrderId ?? ''),
              ),
              Wrap(
                alignment: WrapAlignment.end,
                spacing: 5,
                children: [
                  Visibility(
                      visible: ref
                          .read(orderDetailProvider.notifier)
                          .showCancelMethod(data),
                      child: CommonBtnWidget.transparentBtn(
                          onPressed: () {
                            return EPModalBottomSheet.showCMBS(
                                context: context,
                                builder: (context) => OrderCancel(
                                    list: list,
                                    onFooterPressed: () {
                                      ref
                                          .read(orderListProvider.notifier)
                                          .refresh({}, false);
                                    },
                                    distributionOrderId:
                                        data.distributionOrderId ?? ''));
                          },
                          text: S.of(context).cancel,
                          width: 78,
                          height: 32)),
                  Visibility(
                      visible: ref
                          .read(orderDetailProvider.notifier)
                          .showTrackMethod(data),
                      child: CommonBtnWidget.transparentBtn(
                          onPressed: () {
                            appRouter.push(OrderLogisticsRoute(
                                state: data.state ?? '',
                                bizOrderNumber:
                                    data.distributionOrderId ?? ''));
                          },
                          text: S.of(context).pLogistics,
                          height: 32)),
                  Visibility(
                      visible: ref
                          .read(orderDetailProvider.notifier)
                          .showPayMethod(data),
                      child: CommonBtnWidget.generalBtn(() {
                        appRouter.push(PayListRoute(
                          distributionOrderId: data.distributionOrderId ?? '',
                        ));
                        FirebaseAnalyticsUtils.logEvent(
                            name: PointConstant.orderPay,
                            parameters: {
                              'orderNo': data.distributionOrderId,
                              'pageName':
                                  RouteInfoEnum.getInfo(appRouter.current.name)
                                      .routeZhName
                            });
                      },
                          color: ColorConstant.primaryColor,
                          textStyle: const TextStyle(
                            color: Colors.white,
                            fontSize: FontConstant.f11,
                          ),
                          text: S.current.order_status_to_pay,
                          width: 78,
                          height: 32))
                ],
              )
            ],
          )),
    );
  }
}
